package reflect;


import java.lang.reflect.Method;

/**
 * @author liyang
 * @version 1.0
 * @package reflect
 * @file ReflectDemo5.java
 * @description
 * @time 2024/6/24 上午11:26
 */
public class ReflectDemo5 {
    public static void main(String[] args) throws Exception {
        Person p = new Person();
        p.say("你好呀");
        /*用反射机制调用有参方法*/
        Class cls = Class.forName("reflect.Person");
        Object obj = cls.newInstance();
        Method method = cls.getMethod("say", String.class);
        method.invoke(obj,"大噶好啊");

        Method method1 = cls.getMethod("say", String.class,int.class);
        method1.invoke(obj,"嘿嘿",5);
    }
}
